/***************************************************************************
 *                                                                         *
 * Copyright (c) 2007 - 2009 Nuvoton Technology Corp. All rights reserved.*
 *                                                                         *
 ***************************************************************************/
 
#ifdef ECOS
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "drv_api.h"
#include "diag.h"
#include "wbio.h"
#include "NUC900_GE.h"
#include "NUC900_reg.h"
#else
#include <stdio.h>
#include "NUC900_GE.h"
#include "wbio.h"
#ifdef _NUC900_
#include "NUC900_reg.h"
#else
#include "reg702.h"
#endif
#endif

void memory_copy(void *dest_addr, void *src_addr, int count)
{
  UINT32 cmd32, width, height, pitch, src_start, dest_start, dimension;
  UINT32 temp_misc;
  UINT32 byte_count;

  temp_misc = inpw(REG_2D_GEMC);
  
  /* use 8-BPP */
  outpw(REG_2D_GEMC, temp_misc & 0xffffffcf); // filter always uses 8-BPP

  cmd32 = 0x00430000;
  outpw(REG_2D_GEC, cmd32);
  
  byte_count = count;
  src_start = (UINT32)src_addr;
  dest_start = (UINT32)dest_addr;
    
  while (byte_count > 0x400000)
  {
    width = 2048;
    height = 2048;
    
    pitch = (width << 16) | width;
    outpw(REG_2D_GESDP, pitch);    
    
    outpw(REG_2D_GEXYSORG, src_start);
    outpw(REG_2D_GESSXYL, 0);  
    
    outpw(REG_2D_GEXYDORG, dest_start);    
    outpw(REG_2D_GEDSXYL, 0);

    dimension = height << 16 | width;
    outpw(REG_2D_GEDIXYL, dimension);      
    
    byte_count -= 0x400000;
    src_start += 0x400000;
    dest_start += 0x400000;
    
    outpw(REG_2D_GETG, 1); 
    
    while ((inpw(REG_2D_GEINTS)&0x01)==0); // wait for command complete  

    outpw(REG_2D_GEINTS, 1); // clear interrupt status    
  }
  
  
  
  
  while ((inpw(REG_2D_GEINTS)&0x01)==0); // wait for command complete  

  outpw(REG_2D_GEINTS, 1); // clear interrupt status    

  outpw(REG_2D_GEMC, temp_misc); // restore BPP
}

